﻿
function getParams() {
    var params = {};

    var aliPayCardName = $("input[name='aliPayCardName']").val();
    if (!FlashPay.Util.isNullOrEmptySpance(aliPayCardName)) {
        params.aliPayCardName = aliPayCardName;
    }

    var companyName = $("input[name='companyName']").val();
    if (!FlashPay.Util.isNullOrEmptySpance(companyName)) {
        params.companyName = companyName;
    }

    var bankName = $("input[name='bankName']").val();
    if (!FlashPay.Util.isNullOrEmptySpance(bankName)) {
        params.bankName = bankName;
    }


    var cardNumber = $("input[name='cardNumber']").val();
    if (!FlashPay.Util.isNullOrEmptySpance(cardNumber)) {
        params.cardNumber = cardNumber;
    }

    var cardName = $("input[name='cardName']").val();
    if (!FlashPay.Util.isNullOrEmptySpance(cardName)) {
        params.cardName = cardName;
    }

    var cardType = $("select[name='cardType']").find("option:selected").val();
    if (!FlashPay.Util.isNullOrEmptySpance(cardType)) {
        params.cardType = cardType;
    }

    var enableStatus = $("select[name='enableStatus']").find("option:selected").val();
    if (!FlashPay.Util.isNullOrEmptySpance(enableStatus)) {
        params.enableStatus = enableStatus;
    }

    var authStatus = $("select[name='authStatus']").find("option:selected").val();
    if (!FlashPay.Util.isNullOrEmptySpance(authStatus)) {
        params.authStatus = authStatus;
    }
    return params;
}

function doSearch() {

    var paymentCardColumns = [[
        { field: 'displayOrderNo', title: '订单号', width: 150, align: 'left' },
        { field: 'cmCode', title: '卡商代号', width: 100, align: 'left' },
        { field: 'companyName', title: '公司名称', width: 100, align: 'left' },
        { field: 'companyNameEN', title: '公司英文名称', width: 100, align: 'left' },
        { field: 'bankName', title: '银行名称', width: 100, align: 'left' },
        { field: 'cardName', title: '用户名', width: 75, align: 'left' },
        {
            field: 'cardNumberText', title: '银行卡号', width: 125, align: 'left',
            formatter: function (val, row) {
                return FlashPay.Util.SubCardNumber(val);
            }
        },
        {
            field: 'secCardNumber', title: '副卡号', width: 125, align: 'left',
            formatter: function (val, row) {
                return FlashPay.Util.SubCardNumber(val);
            }
        },
        {
            field: 'cardType', title: '类型', width: 75, align: 'center',
            formatter: function (val, row) {
                return FlashPay.Util.GetCardTypeValue(val);
            }
        },
        {
            field: 'usingStatus', title: '使用状态', width: 75, align: 'center',
            formatter: function (val, row) {
                return FlashPay.Util.GetCardStatusValue(val);
            }
        },
        {
            field: 'enableStatus', title: '启用状态', width: 75, align: 'center',
            formatter: function (val, row) {
                return FlashPay.Util.GetCardEnableStatusValue(val);
            }
        },
        { field: 'paymentInterval', title: '付款区间起迄', width: 125, align: 'right' },
        { field: 'payFeeRatio', title: '付款费率(%)', width: 100, align: 'right' },
        {
            field: 'crossBankPay', title: '跨行转账', width: 100, align: 'left',
            formatter: function (val, row) {
                return FlashPay.Util.GetCrossBankPayValue(val);
            }
        },
        {
            field: 'depositType', title: '存款等级', width: 120, align: 'left',
            formatter: function (val, row) {
                return val;
            }
        },
        { field: 'aliPayCardName', title: '支付宝姓名', width: 130, align: 'left' },
        { field: 'remark', title: '备注', width: 130, align: 'left' },
        {
            field: 'bcId', title: '操作', width: 150, align: 'center',
            formatter: function (val, item) {
                var result = '';

                if (item.enableStatus == 1) {
                    result = '<a class="btn btn-warning btn-xs" data-confirm="{0}<br>确定要<span class=orange>禁用</span>该银行卡？" data-href="/Bank/UpdateStatus?id={1}&status=2">禁用</a>'.format(item.cardName, item.bcId);
                    result += '<button type="button" class="btn btn-default btn-xs" data-href="/view/bankcard/obsoletecardedit.html?id={0}" data-title="查看 - {1}" data-width="460" data-height="650" onclick="return dialogOpen(this);"><span class="glyphicon glyphicon-edit"></span> 查看</button>'.format(item.bcId, item.cardName);
                } else {
                    result = '<a class="btn btn-success btn-xs" data-confirm="{0}<br>确定要<span class=orange>启用</span>该银行卡？" data-href="/Bank/UpdateStatus?id={1}&status=1">启用</a>'.format(item.cardName, item.bcId);
                    result += '<button type="button" class="btn btn-default btn-xs" data-href="/view/bankcard/edit.html?id={0}" data-title="编辑 - {1}" data-width="452" data-height="550" onclick="return dialogOpen(this);"><span class="glyphicon glyphicon-edit"></span> 编辑</button>'.format(item.bcId, item.cardName);
                }
                return result;
            }
        }
    ]];

    var otherCardColumns = [[
        { field: 'displayOrderNo', title: '订单号', width: 150, align: 'left' },
        { field: 'cmCode', title: '卡商代号', width: 100, align: 'left' },
        { field: 'companyName', title: '公司名称', width: 100, align: 'left' },
        { field: 'companyNameEN', title: '公司英文名称', width: 100, align: 'left' },
        { field: 'bankName', title: '银行名称', width: 100, align: 'left' },
        { field: 'cardName', title: '用户名', width: 100, align: 'left' },
        {
            field: 'cardNumber', title: '银行卡号', width: 125, align: 'left',
            formatter: function (val, item) {
                return FlashPay.Util.SubCardNumber(val);
            }
        },
        {
            field: 'secCardNumber', title: '副卡号', width: 125, align: 'left',
            formatter: function (val, item) {
                return FlashPay.Util.SubCardNumber(val);
            }
        },
        {
            field: 'cardType', title: '类型', width: 75, align: 'center',
            formatter: function (val, item) {
                return FlashPay.Util.GetCardTypeValue(val);
            }
        },
        {
            field: 'usingStatus', title: '使用状态', width: 75, align: 'center',
            formatter: function (val, row) {
                return FlashPay.Util.GetCardStatusValue(val);
            }
        },
        {
            field: 'enableStatus', title: '启用状态', width: 75, align: 'center',
            formatter: function (val, row) {
                return FlashPay.Util.GetCardEnableStatusValue(val);
            }
        },
        { field: 'createName', title: '建立人员', width: 125, align: 'left' },
        { field: 'aliPayCardName', title: '支付宝姓名', width: 130, align: 'left' },
        { field: 'remark', title: '备注', width: 130, align: 'left' },
        {
            field: 'bcId', title: '操作', width: 125, align: 'center',
            formatter: function (val, item) {

                var result = '';

                if (item.enableStatus == 1) {
                    result = '<a class="btn btn-warning btn-xs" data-confirm="{0}<br>确定要<span class=orange>禁用</span>该银行卡？" data-href="/Bank/UpdateStatus?id={1}&status=2">禁用</a>'.format(item.cardName, item.bcId);
                    result += '<button type="button" class="btn btn-default btn-xs" data-href="/view/bankcard/obsoletecardedit.html?id={0}" data-title="查看 - {1}" data-width="460" data-height="650" onclick="return dialogOpen(this);"><span class="glyphicon glyphicon-edit"></span> 查看</button>'.format(item.bcId, item.cardName);
                } else {
                    result = '<a class="btn btn-success btn-xs" data-confirm="{0}<br>确定要<span class=orange>启用</span>该银行卡？" data-href="/Bank/UpdateStatus?id={1}&status=1">启用</a>'.format(item.cardName, item.bcId);
                    result += '<button type="button" class="btn btn-default btn-xs" data-href="/view/bankcard/edit.html?id={0}" data-title="编辑 - {1}" data-width="452" data-height="550" onclick="return dialogOpen(this);"><span class="glyphicon glyphicon-edit"></span> 编辑</button>'.format(item.bcId, item.cardName);
                }
                return result;
            }
        }
    ]];

    var cardType = $("#cardType option:selected").val();

    var columns = cardType == 3 ? paymentCardColumns : otherCardColumns;

    $("#indexB2B").datagrid({
        fit: false,
        loadMsg: '数据加载中，请稍后……',
        method: "get",
        border: true,
        url: "/Bank/GetPager",
        queryParams: getParams(),
        pagination: true,
        pageSize: pageSize,
        pageList: [15, 30, 50, 100, 1000],
        height: $(window).height() - 70,
        singleSelect: true,
        //fitColumns: true,
        rownumbers: true,
        showFooter: true,
        columns: columns,
        onLoadSuccess: function (data) {
            pageSize = $('#indexB2B').datagrid('options').pageSize;
        }
    });
}